/*
 * @lc app=leetcode.cn id=942 lang=javascript
 *
 * [942] 增减字符串匹配
 */

// @lc code=start
/**
 * @param {string} s
 * @return {number[]}
 */
var diStringMatch = function (s) {
  let max = s.length;
  let min = 0;
  const result = [];
  for (let i = 0; i < s.length; i++) {
    if (s.charAt(i) === 'I') {
      result.push(min++);
    } else {
      result.push(max--);
    }
  }
  return result.concat(min);
};
// @lc code=end
